package com.szrt.java.day20161226.demo09;

import java.util.Scanner;

public class CalIfElse {

	public static void main(String[] args) {
		
		while(true){
			Scanner sc = new Scanner(System.in);
			
			System.out.println("请输入运算符号，如：+ - * / % (若要推出则输入：quit)");
			String symbol = sc.next();
			
			System.out.println("请输入第1个数：");
			int one = sc.nextInt();
			
			System.out.println("请输入第2个数：");
			int two = sc.nextInt();
			
			if(symbol.equals("quit")){
				break;
			}
			sc.close();
			
			cal(symbol,one,two);
		}
		
		
	}
	
	public static void cal(String symbol,int one,int two){
		
		if(symbol.equals("+")){
			add(one,two);
		}else if(symbol.equals("-")){
			sub(one,two);
		}else if(symbol.equals("*")){
			cheng(one,two);
		}else if(symbol.equals("/")){
			if(two==0){
				System.out.println("0");
			}
			chu(one,two);
		}else if(symbol.equals("%")){
			mod(one,two);
		}
	}
		
	/**
	 * 计算两个数之和
	 * @param a 
	 * @param b
	 * @return
	 */
	public static int add(int a,int b){
		int result = a+b;
		System.out.println(result);
		return result;
	}
	
	/**
	 * 计算两个数之差
	 * @param a
	 * @param b
	 * @return
	 */
	public static int sub(int a,int b){
		int result = a-b;
		System.out.println(result);
		return result;
	}
	
	/**
	 * 计算两个数相乘
	 * @param a
	 * @param b
	 * @return
	 */
	public static int cheng(int a,int b){
		int result = a*b;
		System.out.println(result);
		return result;
	}
	
	/**
	 * 两个数求模
	 * @param a
	 * @param b
	 * @return
	 */
	public static int chu(int a,int b){
		int result = a/b;
		System.out.println(result);
		return result;
	}
	
	/**
	 * 
	 * @param a
	 * @param b
	 * @return
	 */
	public static int mod(int a,int b){
		int result = a%b;
		System.out.println(result);
		return result;
	}
	
}
